package cn.gson.springboot.model.service;

import cn.gson.springboot.model.dao.ApprovalDao;
import cn.gson.springboot.model.mapper.ApprovalMapper;
import cn.gson.springboot.model.pojos.Approval;
import cn.gson.springboot.model.vo.ApprovalVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Date;
import java.sql.Time;
import java.sql.Timestamp;
import java.util.List;

@Service
public class ApprovalService {
    @Autowired
    ApprovalMapper appMapper;
    @Autowired
    ApprovalDao appDao;

    public List<Approval> selectAllApproval(Integer type,Integer num,Integer empId,String appTheme){
        return appMapper.selectAllApproval(type,num,empId,appTheme);
    }

    public Approval selectApprovalByQuoId(Integer quoId){
        return appMapper.selectApprovalByQuoId(quoId);
    }

    public Approval selectApprovalByPurId(Integer purId){
        return appMapper.selectApprovalByPurId(purId);
    }

    public Approval selectApprovalByBusId(Integer businessId){
        return appMapper.selectApprovalByBusId(businessId);
    }

    public Approval selectApprovalByConId(Integer conId){
        return appMapper.selectApprovalByConId(conId);
    }

    public Approval selectApprovalByPayPlanId(Integer payId){
        return appMapper.selectApprovalByPayPlanId(payId);
    }

    public Approval selectApprovalByAppId(Integer appId){
        return appMapper.selectApprovalByAppId(appId);
    }

    public Approval selectAppByAppIdAndClassify(Approval app){
        return appMapper.selectAppByAppIdAndClassify(app);
    }

    public List<Approval> selectApprovalByStatus(Integer appStatus){
        return appMapper.selectApprovalByStatus(appStatus);
    }

    public List<Approval> selectApprovalByTheme(String appTheme){
        return appMapper.selectApprovalByTheme(appTheme);
    }

    public void saveApproval(ApprovalVo vo){
        Approval app = new Approval();
        app.setApprovalId(vo.getApprovalId());
        app.setEmployeeByApplicantEmpId(vo.getEmployeeByApplicantEmpId());
        app.setApprovalContent(vo.getApprovalContent());
        app.setApprovalTheme(vo.getApprovalTheme());
        app.setApprovalContent(vo.getApprovalContent());
        app.setApprovalStay(vo.getApprovalStay());
        app.setApprovalDate(vo.getApprovalDate());
        app.setApprovalStatus(vo.getApprovalStatus());
        app.setApprovalClassify(vo.getApprovalClassify());
        app.setApprovalOperation(vo.getApprovalOperation());
        if (vo.getApprovalId() == 0){
            app.setApprovalTime(new Timestamp(System.currentTimeMillis()));
        }else {
            app.setApprovalTime(vo.getApprovalTime());
        }
        app.setEmployeeByApprovalEmpId(vo.getEmployeeByApprovalEmpId());
        app.setQuotationByQuotationId(vo.getQuotationByQuotationId());
        app.setBusinesstripByBusinessId(vo.getBusinesstripByBusinessId());
        app.setPurchaseByPurchaseId(vo.getPurchaseByPurchaseId());
        app.setContractByContractId(vo.getContractByContractId());
        app.setPaymentPlanByPaymentPlanId(vo.getPaymentPlanByPaymentPlanId());
        appDao.save(app);
    }

}
